<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * This file contains the PDODB_Function_oci class.
 *
 * PHP version 5
 *
 * This file is part of PEAR::PDODB - A database abstraction layer for PHP5 built
 * using PDO. PHP version 5.1+ is recommended.
 *
 * PEAR::PDODB is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * PEAR::PDODB is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with PEAR::PDODB. If not, see <http://www.gnu.org/licenses/>.
 *
 * @package     PDODB
 * @subpackage  oci
 * @category    Database
 * @author      Lukas Smith <smith@pooteeweet.org>
 * @author      Michael J. I. Jackson <mjijackson@gmail.com>
 * @copyright   1998-2007 Manuel Lemos, Tomas V.V. Cox, Stig S. Bakken, Lukas Smith
 * @copyright   2007 Michael J. I. Jackson
 * @license     http://www.gnu.org/licenses/lgpl-3.0.txt GNU LGPL 3.0
 * @version     SVN: $Id: oci.php 2 2007-11-27 17:20:29Z mjijackson $
 * @link        http://pear.php.net/packages/PDODB
 */

/**
 * Require PDODB_Function
 */
require_once dirname(__FILE__) . '.php';

/**
 * An OCI-specific function module class.
 *
 * @package     PDODB
 * @category    Database
 * @author      Lukas Smith <smith@pooteeweet.org>
 * @author      Michael J. I. Jackson <mjijackson@gmail.com>
 */
class PDODB_Function_oci extends PDODB_Function
{

    /**
     * @see     PDODB_Function::executeStoredProc()
     */
    public function executeStoredProc($name, $params = null)
    {
        $db = $this->getConnection();
        $query = 'EXEC ' . $name
            . ($params ? '(' . implode(', ', $params) . ')' : '()');
        return $db->query($query);
    }

    /**
     * @see     PDODB_Function::functionTable()
     */
    public function functionTable()
    {
        return ' FROM dual';
    }

    /**
     * @see     PDODB_Function::now()
     */
    public function now($type = 'timestamp')
    {
        switch ($type) {
        case 'date':
        case 'time':
        case 'timestamp':
        default:
            return 'TO_CHAR(CURRENT_TIMESTAMP, \'YYYY-MM-DD HH24:MI:SS\')';
        }
    }

    /**
     * @see     PDODB_Function::substring()
     */
    public function substring($value, $position = 1, $length = null)
    {
        if (!is_null($length)) {
            return "SUBSTR($value, $position, $length)";
        }

        return "SUBSTR($value, $position)";
    }

    /**
     * @see     PDODB_Function::random()
     */
    public function random()
    {
        return 'dbms_random.value';
    }

    /**
     * @see     PDODB_Function::guid()
     */
    public function guid()
    {
        return 'SYS_GUID()';
    }

}

?>
